package fplaton.helper;

import java.awt.event.FocusEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JTextField;

/**
 * @desc Input validation methods
 * @author dastergon
 */
public class Validation {

    /**
     * Empty and null validation
     *
     * @param name
     * @return true valid string, false empty string
     */
    public static boolean isNullorEmpty(String name) {
        return name == null || name.isEmpty();
    }

    /**
     * Integer validation
     *
     * @param str
     * @return true valid int, false invalid int
     */
    public static boolean isInteger(String str) {
        try {
            Integer.parseInt(str);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    /**
     * Email validation
     *
     * @param email
     * @return
     */
    public static boolean isEmail(String email) {
        String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
                + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
        Matcher matcher;
        Pattern pattern;

        pattern = Pattern.compile(EMAIL_PATTERN);
        matcher = pattern.matcher(email);
        return matcher.matches();
    }
    
    /** Characters validation
     * @param courseName
     * @return 
    **/
    public static boolean isChar(String courseName){
       try { 
            return courseName.matches("[Α-ΩA-Z ,.]+");
       } catch (NumberFormatException e){
            return false;
        }
    }
}
